package org.deadline.model.baseapp;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.config.Enumeration;
import org.deadline.model.user.Person;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class Event extends BaseEntity  implements Serializable {

    @ManyToOne
    private Enumeration eventType;

    @NotNull
    @ManyToOne
    private Person person;

    private String targetUserss;

    private String destinationUsers;

    @NotNull
    @Size(min = 2, max = 255)
    private String description;

    @NotNull
    @Size(min = 8, max = 30)
    private String externalClientIp;

    @NotNull
    @Size(min = 8, max = 30)
    private String internalIp;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="event_seq_gen",sequenceName="event_seq")
	@GeneratedValue(generator="event_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static Event fromJsonToEvent(String json) {
        return new JSONDeserializer<Event>().use(null, Event.class).deserialize(json);
    }

	public static String toJsonArray(Collection<Event> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<Event> fromJsonArrayToEvents(String json) {
        return new JSONDeserializer<List<Event>>().use(null, ArrayList.class).use("values", Event.class).deserialize(json);
    }

	public Enumeration getEventType() {
        return this.eventType;
    }

	public void setEventType(Enumeration eventType) {
        this.eventType = eventType;
    }

	public Person getPerson() {
        return this.person;
    }

	public void setPerson(Person person) {
        this.person = person;
    }

	public String getTargetUserss() {
        return this.targetUserss;
    }

	public void setTargetUserss(String targetUserss) {
        this.targetUserss = targetUserss;
    }

	public String getDestinationUsers() {
        return this.destinationUsers;
    }

	public void setDestinationUsers(String destinationUsers) {
        this.destinationUsers = destinationUsers;
    }

	public String getDescription() {
        return this.description;
    }

	public void setDescription(String description) {
        this.description = description;
    }

	public String getExternalClientIp() {
        return this.externalClientIp;
    }

	public void setExternalClientIp(String externalClientIp) {
        this.externalClientIp = externalClientIp;
    }

	public String getInternalIp() {
        return this.internalIp;
    }

	public void setInternalIp(String internalIp) {
        this.internalIp = internalIp;
    }

	
	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}


	private static final long serialVersionUID = 1L;
}
